package com.cyx.gametool.mgr;

import com.cyx.gametool.controller.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Controller管理器
 */
public class ControllerMgr {

    private final Map<String, AbsBaseController> controllers = new HashMap<String, AbsBaseController>();

    public static ControllerMgr getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void addController(AbsBaseController controller) {
        controllers.put(controller.getClass().getSimpleName(), controller);
    }

    public AbsBaseController getController(String simpleName) {
        return controllers.get(simpleName);
    }

    public AbsBaseController getController(Class<? extends AbsBaseController> clazz) {
        return controllers.get(clazz.getSimpleName());
    }

    public ExcelConfigController getExcelConfigController() {
        return (ExcelConfigController) ControllerMgr.getInstance().getController(ExcelConfigController.class);
    }

    public ExcelToJavaController getExcelToJavaController() {
        return (ExcelToJavaController) ControllerMgr.getInstance().getController(ExcelToJavaController.class);
    }

    public ExcelToJsonController getExcelToJsonController() {
        return (ExcelToJsonController) ControllerMgr.getInstance().getController(ExcelToJsonController.class.getSimpleName());
    }

    public ExcelToMysqlController getExcelToMysqlController() {
        return (ExcelToMysqlController) ControllerMgr.getInstance().getController(ExcelToMysqlController.class.getSimpleName());
    }


    // 单例模式
    private static class SingletonHolder {
        private static final ControllerMgr INSTANCE = new ControllerMgr();
    }
}
